//
//  SchemeCell.m
//  liangyi
//
//  Created by 张水 on 17/1/12.
//  Copyright © 2017年 yswh. All rights reserved.
//

#import "SchemeCell.h"

@interface SchemeCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong) NSMutableArray *Arrdata;

@end

@implementation SchemeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.Arrdata = [NSMutableArray array];
        [self initialize];
    }
    return self;
}

-(void)setModel:(StageModel *)model{
    _model = model;
    self.desLabel.text = [NSString stringWithFormat:@"%@   %@",model.title,model.content];
//    [self.Arrdata removeAllObjects];
//    [self.Arrdata addObjectsFromArray:model.recoveries];
//    self.Arrdata = [recoveriesModel mj_objectArrayWithKeyValuesArray:self.Arrdata];
//    [self.collectionView reloadData];
    [self.Arrdata removeAllObjects];
    [self.Arrdata addObjectsFromArray:model.recoveries];
    self.Arrdata = [recoveriesModel mj_objectArrayWithKeyValuesArray:self.Arrdata];
    [self.collectionView reloadData];
}

//-(void)loadSchemeData:(StageModel *)model{
////    _model = model;
//    StageModel *data = [StageModel mj_objectWithKeyValues:model];
//    NSLog(@"%@--%@--%@",data,data.title,data.content);
//    self.desLabel.text = [NSString stringWithFormat:@"%@   %@",data.title,data.content];
////    [self.Arrdata removeAllObjects];
////    [self.Arrdata addObjectsFromArray:data.recoveries];
////    self.Arrdata = [recoveriesModel mj_objectArrayWithKeyValuesArray:self.Arrdata];
////    [self.collectionView reloadData];
//}
-(void)initialize{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UILabel *backlable = [[UILabel alloc]init];
    backlable.backgroundColor = [UIColor ColorWithHex:@"#5BC9D7"];
    [self.contentView addSubview:backlable];
    [backlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.right.equalTo(self);
        make.height.equalTo(@40);
    }];
    

    self.desLabel = [[UILabel alloc]init];
    self.desLabel.backgroundColor = [UIColor  clearColor];
    self.desLabel.numberOfLines = 0;
    self.desLabel.font = [UIFont systemFontOfSize:16];
    self.desLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.desLabel];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self).offset(10);
        make.height.equalTo(@40);
    }];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.itemSize = CGSizeMake(150, 120);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    [self.collectionView registerClass:[ImageViewCell class] forCellWithReuseIdentifier:@"ImageViewCell"];
    [self addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(50);
        make.left.equalTo(self).offset(5);
        make.right.equalTo(self).offset(-5);
        make.height.equalTo(@120);
    }];
    
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return  self.Arrdata.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ImageViewCell *collectioncell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageViewCell" forIndexPath:indexPath];
    recoveriesModel *model = self.Arrdata[indexPath.item];
    [collectioncell.schemeImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",BaseIamgeUrl,model.videoImg]] placeholderImage:[UIImage imageNamed:@"img_placeholder"]];
    return  collectioncell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(170, 120);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    recoveriesModel *model = self.dataArr[indexPath.item];
//    NSDictionary *dict = @{@"indexPath":indexPath,
//                           @"title":model.title,
//                           @"rid":model.id};// @"videoAddress":model.videoAddress,
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"JumpToDetailVideoViewController" object:self userInfo:dict];
    [CustomProgressHUD showSuccessWithStatus:@"该视频暂时不能观看,您可以观看您定制的康复计划方案中的视频"];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
}

@end
